﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;


namespace Surveillance
{
    public class PressurePlate
    {
        #region switch declarations

        public static Texture2D plateTexture;
        private Vector2 worldPosition;
        private Rectangle targetRectangle;
        private List<Switchable> linkedTo;
        private int switchToState;


        #endregion

        #region switch constructors

        public PressurePlate(Vector2 position, int width, int height, int switchTo)
        {
            worldPosition = position;
            targetRectangle = new Rectangle((int)position.X, (int)position.Y, width, height);
            switchToState = switchTo;
            linkedTo = new List<Switchable>();
        }

        #endregion

        #region switch update and draw


        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(
               plateTexture,
               targetRectangle,
               null,
               Color.White,
               0.0f,
               Vector2.Zero,
               SpriteEffects.None,
               0.0f);
        }

        #endregion

        #region switch auxiliary

    

        public void stepOn()
        {
            
            foreach (Switchable link in linkedTo)
            {
                link.doSwitch(switchToState);
            }
        }

        public void addLink(Switchable link)
        {
            linkedTo.Add(link);
        }

        #endregion

        #region switch properties

        public Rectangle TargetRectangle
        {
            get { return targetRectangle; }
            set { targetRectangle = value; }
        }

        #endregion
    }
}
